{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1读取数据\n",
    "# 2数据预处理\n",
    "## 2.1给数据添加时间维度\n",
    "## 2.2选取平稳数列\n",
    "# 3RuleBased模型\n",
    "## 3.1计算周期因子\n",
    "## 3.2统计频次\n",
    "## 3.3按照rule_based方式计算预测结果\n",
    "## 4输出结果与提交"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>report_date</th>\n",
       "      <th>tBalance</th>\n",
       "      <th>yBalance</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>direct_purchase_amt</th>\n",
       "      <th>purchase_bal_amt</th>\n",
       "      <th>purchase_bank_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>consume_amt</th>\n",
       "      <th>transfer_amt</th>\n",
       "      <th>tftobal_amt</th>\n",
       "      <th>tftocard_amt</th>\n",
       "      <th>share_amt</th>\n",
       "      <th>category1</th>\n",
       "      <th>category2</th>\n",
       "      <th>category3</th>\n",
       "      <th>category4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>20140805</td>\n",
       "      <td>20385</td>\n",
       "      <td>20383</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>20140808</td>\n",
       "      <td>20391</td>\n",
       "      <td>20389</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>20140811</td>\n",
       "      <td>20397</td>\n",
       "      <td>20395</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>20140814</td>\n",
       "      <td>20403</td>\n",
       "      <td>20401</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>20140817</td>\n",
       "      <td>20409</td>\n",
       "      <td>20407</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840416</th>\n",
       "      <td>28033</td>\n",
       "      <td>20140825</td>\n",
       "      <td>550646</td>\n",
       "      <td>550585</td>\n",
       "      <td>61</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>61</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840417</th>\n",
       "      <td>28033</td>\n",
       "      <td>20140831</td>\n",
       "      <td>525707</td>\n",
       "      <td>538147</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>12500</td>\n",
       "      <td>12500</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>60</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840418</th>\n",
       "      <td>28033</td>\n",
       "      <td>20140724</td>\n",
       "      <td>20487121</td>\n",
       "      <td>20484824</td>\n",
       "      <td>2297</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2297</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840419</th>\n",
       "      <td>28033</td>\n",
       "      <td>20140727</td>\n",
       "      <td>20462288</td>\n",
       "      <td>20491722</td>\n",
       "      <td>2298</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>31732</td>\n",
       "      <td>0</td>\n",
       "      <td>31732</td>\n",
       "      <td>0</td>\n",
       "      <td>31732</td>\n",
       "      <td>2298</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840420</th>\n",
       "      <td>28035</td>\n",
       "      <td>20140305</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2840421 rows × 18 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         user_id  report_date  tBalance  yBalance  total_purchase_amt  \\\n",
       "0              1     20140805     20385     20383                   2   \n",
       "1              1     20140808     20391     20389                   2   \n",
       "2              1     20140811     20397     20395                   2   \n",
       "3              1     20140814     20403     20401                   2   \n",
       "4              1     20140817     20409     20407                   2   \n",
       "...          ...          ...       ...       ...                 ...   \n",
       "2840416    28033     20140825    550646    550585                  61   \n",
       "2840417    28033     20140831    525707    538147                  60   \n",
       "2840418    28033     20140724  20487121  20484824                2297   \n",
       "2840419    28033     20140727  20462288  20491722                2298   \n",
       "2840420    28035     20140305         0         0                   0   \n",
       "\n",
       "         direct_purchase_amt  purchase_bal_amt  purchase_bank_amt  \\\n",
       "0                          0                 0                  0   \n",
       "1                          0                 0                  0   \n",
       "2                          0                 0                  0   \n",
       "3                          0                 0                  0   \n",
       "4                          0                 0                  0   \n",
       "...                      ...               ...                ...   \n",
       "2840416                    0                 0                  0   \n",
       "2840417                    0                 0                  0   \n",
       "2840418                    0                 0                  0   \n",
       "2840419                    0                 0                  0   \n",
       "2840420                    0                 0                  0   \n",
       "\n",
       "         total_redeem_amt  consume_amt  transfer_amt  tftobal_amt  \\\n",
       "0                       0            0             0            0   \n",
       "1                       0            0             0            0   \n",
       "2                       0            0             0            0   \n",
       "3                       0            0             0            0   \n",
       "4                       0            0             0            0   \n",
       "...                   ...          ...           ...          ...   \n",
       "2840416                 0            0             0            0   \n",
       "2840417             12500        12500             0            0   \n",
       "2840418                 0            0             0            0   \n",
       "2840419             31732            0         31732            0   \n",
       "2840420                 0            0             0            0   \n",
       "\n",
       "         tftocard_amt  share_amt  category1  category2  category3  category4  \n",
       "0                   0          2        NaN        NaN        NaN        NaN  \n",
       "1                   0          2        NaN        NaN        NaN        NaN  \n",
       "2                   0          2        NaN        NaN        NaN        NaN  \n",
       "3                   0          2        NaN        NaN        NaN        NaN  \n",
       "4                   0          2        NaN        NaN        NaN        NaN  \n",
       "...               ...        ...        ...        ...        ...        ...  \n",
       "2840416             0         61        NaN        NaN        NaN        NaN  \n",
       "2840417             0         60        0.0        0.0        0.0    12500.0  \n",
       "2840418             0       2297        NaN        NaN        NaN        NaN  \n",
       "2840419         31732       2298        NaN        NaN        NaN        NaN  \n",
       "2840420             0          0        NaN        NaN        NaN        NaN  \n",
       "\n",
       "[2840421 rows x 18 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=pd.read_csv('user_balance_table.csv')\n",
    "data#user_id就是用户 report_date是日期 tBalance是今日余额  yBalance是昨日余额  total_purchase_amt 今日总购买量（=直接购买+收益）\n",
    "#direct_purchase_amt是直接购买  purchase_bal_amt今日支付宝余额购买量  purchase_bank_amt今日银行卡购买量 \n",
    "#total_redeem_amt今日总赎回量（=消费+转出） consume_amt今日总消费量 transfer_amt今日转出总量   \n",
    "#tftobal_amt今日转出到支付宝余额总量 tftocard_amt今日转出到银行卡总量   share_amt今日收益\n",
    "#category1 category2 category3 category4分别表示类目1 2 3 4 消费总额\n",
    "#其中 total_purchase_amt 和 total_redeem_amt 是我们要预测的目标值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2数据预处理"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.1给数据添加时间维度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:9: FutureWarning: Series.dt.weekofyear and Series.dt.week have been deprecated.  Please use Series.dt.isocalendar().week instead.\n",
      "  if __name__ == '__main__':\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>report_date</th>\n",
       "      <th>tBalance</th>\n",
       "      <th>yBalance</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>direct_purchase_amt</th>\n",
       "      <th>purchase_bal_amt</th>\n",
       "      <th>purchase_bank_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>consume_amt</th>\n",
       "      <th>...</th>\n",
       "      <th>share_amt</th>\n",
       "      <th>category1</th>\n",
       "      <th>category2</th>\n",
       "      <th>category3</th>\n",
       "      <th>category4</th>\n",
       "      <th>day</th>\n",
       "      <th>month</th>\n",
       "      <th>year</th>\n",
       "      <th>week</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-05</td>\n",
       "      <td>20385</td>\n",
       "      <td>20383</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>32</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-08</td>\n",
       "      <td>20391</td>\n",
       "      <td>20389</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>32</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-11</td>\n",
       "      <td>20397</td>\n",
       "      <td>20395</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>11</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>33</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-14</td>\n",
       "      <td>20403</td>\n",
       "      <td>20401</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>14</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>33</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-17</td>\n",
       "      <td>20409</td>\n",
       "      <td>20407</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>17</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>33</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840416</th>\n",
       "      <td>28033</td>\n",
       "      <td>2014-08-25</td>\n",
       "      <td>550646</td>\n",
       "      <td>550585</td>\n",
       "      <td>61</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>61</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>25</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840417</th>\n",
       "      <td>28033</td>\n",
       "      <td>2014-08-31</td>\n",
       "      <td>525707</td>\n",
       "      <td>538147</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>12500</td>\n",
       "      <td>12500</td>\n",
       "      <td>...</td>\n",
       "      <td>60</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12500.0</td>\n",
       "      <td>31</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>35</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840418</th>\n",
       "      <td>28033</td>\n",
       "      <td>2014-07-24</td>\n",
       "      <td>20487121</td>\n",
       "      <td>20484824</td>\n",
       "      <td>2297</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2297</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24</td>\n",
       "      <td>7</td>\n",
       "      <td>2014</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840419</th>\n",
       "      <td>28033</td>\n",
       "      <td>2014-07-27</td>\n",
       "      <td>20462288</td>\n",
       "      <td>20491722</td>\n",
       "      <td>2298</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>31732</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2298</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>27</td>\n",
       "      <td>7</td>\n",
       "      <td>2014</td>\n",
       "      <td>30</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840420</th>\n",
       "      <td>28035</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2840421 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         user_id report_date  tBalance  yBalance  total_purchase_amt  \\\n",
       "0              1  2014-08-05     20385     20383                   2   \n",
       "1              1  2014-08-08     20391     20389                   2   \n",
       "2              1  2014-08-11     20397     20395                   2   \n",
       "3              1  2014-08-14     20403     20401                   2   \n",
       "4              1  2014-08-17     20409     20407                   2   \n",
       "...          ...         ...       ...       ...                 ...   \n",
       "2840416    28033  2014-08-25    550646    550585                  61   \n",
       "2840417    28033  2014-08-31    525707    538147                  60   \n",
       "2840418    28033  2014-07-24  20487121  20484824                2297   \n",
       "2840419    28033  2014-07-27  20462288  20491722                2298   \n",
       "2840420    28035  2014-03-05         0         0                   0   \n",
       "\n",
       "         direct_purchase_amt  purchase_bal_amt  purchase_bank_amt  \\\n",
       "0                          0                 0                  0   \n",
       "1                          0                 0                  0   \n",
       "2                          0                 0                  0   \n",
       "3                          0                 0                  0   \n",
       "4                          0                 0                  0   \n",
       "...                      ...               ...                ...   \n",
       "2840416                    0                 0                  0   \n",
       "2840417                    0                 0                  0   \n",
       "2840418                    0                 0                  0   \n",
       "2840419                    0                 0                  0   \n",
       "2840420                    0                 0                  0   \n",
       "\n",
       "         total_redeem_amt  consume_amt  ...  share_amt  category1  category2  \\\n",
       "0                       0            0  ...          2        NaN        NaN   \n",
       "1                       0            0  ...          2        NaN        NaN   \n",
       "2                       0            0  ...          2        NaN        NaN   \n",
       "3                       0            0  ...          2        NaN        NaN   \n",
       "4                       0            0  ...          2        NaN        NaN   \n",
       "...                   ...          ...  ...        ...        ...        ...   \n",
       "2840416                 0            0  ...         61        NaN        NaN   \n",
       "2840417             12500        12500  ...         60        0.0        0.0   \n",
       "2840418                 0            0  ...       2297        NaN        NaN   \n",
       "2840419             31732            0  ...       2298        NaN        NaN   \n",
       "2840420                 0            0  ...          0        NaN        NaN   \n",
       "\n",
       "         category3  category4  day  month  year  week  weekday  \n",
       "0              NaN        NaN    5      8  2014    32        1  \n",
       "1              NaN        NaN    8      8  2014    32        4  \n",
       "2              NaN        NaN   11      8  2014    33        0  \n",
       "3              NaN        NaN   14      8  2014    33        3  \n",
       "4              NaN        NaN   17      8  2014    33        6  \n",
       "...            ...        ...  ...    ...   ...   ...      ...  \n",
       "2840416        NaN        NaN   25      8  2014    35        0  \n",
       "2840417        0.0    12500.0   31      8  2014    35        6  \n",
       "2840418        NaN        NaN   24      7  2014    30        3  \n",
       "2840419        NaN        NaN   27      7  2014    30        6  \n",
       "2840420        NaN        NaN    5      3  2014    10        2  \n",
       "\n",
       "[2840421 rows x 23 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#给数据添加维度\n",
    "def add_timestamp(data):\n",
    "    #时间格式转换\n",
    "    data['report_date']=pd.to_datetime(data['report_date'],format=\"%Y%m%d\")#这就是把哪一列report_date的数据给转成标准时间格式\n",
    "    #添加时间维度\n",
    "    data['day']=data['report_date'].dt.day#1号 2号这样的\n",
    "    data['month']=data['report_date'].dt.month#月\n",
    "    data['year']=data['report_date'].dt.year#年\n",
    "    data['week']=data['report_date'].dt.week#第几个星期\n",
    "    data['weekday']=data['report_date'].dt.weekday#星期几    \n",
    "    return data\n",
    "\n",
    "data=add_timestamp(data)\n",
    "data#这样就有了report_date  后面那几列  查了日历都是对的上的  其中weekday是从0-6代表星期1-日"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6    410701\n",
       "5    408824\n",
       "4    407509\n",
       "3    405907\n",
       "2    404159\n",
       "1    402536\n",
       "0    400785\n",
       "Name: weekday, dtype: int64"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#0代表周一，6代表周日\n",
    "data['weekday'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.2选取平稳数列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:5: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.\n",
      "  \"\"\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             total_purchase_amt  total_redeem_amt\n",
      "report_date                                      \n",
      "2013-07-01             32488348           5525022\n",
      "2013-07-02             29037390           2554548\n",
      "2013-07-03             27270770           5953867\n",
      "2013-07-04             18321185           6410729\n",
      "2013-07-05             11648749           2763587\n",
      "...                         ...               ...\n",
      "2014-08-27            302194801         468164147\n",
      "2014-08-28            245082751         297893861\n",
      "2014-08-29            267554713         273756380\n",
      "2014-08-30            199708772         196374134\n",
      "2014-08-31            275090213         292943033\n",
      "\n",
      "[427 rows x 2 columns]\n",
      "索引还原：\n",
      "     report_date  total_purchase_amt  total_redeem_amt\n",
      "0    2013-07-01            32488348           5525022\n",
      "1    2013-07-02            29037390           2554548\n",
      "2    2013-07-03            27270770           5953867\n",
      "3    2013-07-04            18321185           6410729\n",
      "4    2013-07-05            11648749           2763587\n",
      "..          ...                 ...               ...\n",
      "422  2014-08-27           302194801         468164147\n",
      "423  2014-08-28           245082751         297893861\n",
      "424  2014-08-29           267554713         273756380\n",
      "425  2014-08-30           199708772         196374134\n",
      "426  2014-08-31           275090213         292943033\n",
      "\n",
      "[427 rows x 3 columns]\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>2014-04-01</td>\n",
       "      <td>453320585</td>\n",
       "      <td>277429358</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>2014-04-02</td>\n",
       "      <td>355347118</td>\n",
       "      <td>272612066</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>2014-04-03</td>\n",
       "      <td>363877120</td>\n",
       "      <td>266605457</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>277</th>\n",
       "      <td>2014-04-04</td>\n",
       "      <td>251895894</td>\n",
       "      <td>200192637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>278</th>\n",
       "      <td>2014-04-05</td>\n",
       "      <td>202336542</td>\n",
       "      <td>163199682</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>422</th>\n",
       "      <td>2014-08-27</td>\n",
       "      <td>302194801</td>\n",
       "      <td>468164147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>423</th>\n",
       "      <td>2014-08-28</td>\n",
       "      <td>245082751</td>\n",
       "      <td>297893861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>424</th>\n",
       "      <td>2014-08-29</td>\n",
       "      <td>267554713</td>\n",
       "      <td>273756380</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>425</th>\n",
       "      <td>2014-08-30</td>\n",
       "      <td>199708772</td>\n",
       "      <td>196374134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>426</th>\n",
       "      <td>2014-08-31</td>\n",
       "      <td>275090213</td>\n",
       "      <td>292943033</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>153 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt\n",
       "274  2014-04-01           453320585         277429358\n",
       "275  2014-04-02           355347118         272612066\n",
       "276  2014-04-03           363877120         266605457\n",
       "277  2014-04-04           251895894         200192637\n",
       "278  2014-04-05           202336542         163199682\n",
       "..          ...                 ...               ...\n",
       "422  2014-08-27           302194801         468164147\n",
       "423  2014-08-28           245082751         297893861\n",
       "424  2014-08-29           267554713         273756380\n",
       "425  2014-08-30           199708772         196374134\n",
       "426  2014-08-31           275090213         292943033\n",
       "\n",
       "[153 rows x 3 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#因为前面两个模型的图的趋势看出来了从2014-04-01到2014-08-31  就是数据集中2014-04-01以后的数据  这里为了模型数据量更准确所以多选一点从3月开始\n",
    "def get_total_balance(data,begin):\n",
    "    df_temp=data.copy()#在copy数据上进行操作\n",
    "    #按照 report_date 进行聚合\n",
    "    df_temp=df_temp.groupby(['report_date'])['total_purchase_amt','total_redeem_amt'].sum()\n",
    "    print(df_temp)\n",
    "    df_temp.reset_index(inplace=True)#还原一下索引 然后原来的report_date就成为了一列数据\n",
    "    print(\"索引还原：\\n\",df_temp)\n",
    "    df_temp=df_temp[(df_temp['report_date']>=begin)]\n",
    "    return df_temp\n",
    "        \n",
    "total_balance=get_total_balance(data,'2014-03-01')#这样就得到了3月1号之后的数据\n",
    "total_balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>2014-04-01</td>\n",
       "      <td>453320585.0</td>\n",
       "      <td>277429358.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>2014-04-02</td>\n",
       "      <td>355347118.0</td>\n",
       "      <td>272612066.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>2014-04-03</td>\n",
       "      <td>363877120.0</td>\n",
       "      <td>266605457.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>277</th>\n",
       "      <td>2014-04-04</td>\n",
       "      <td>251895894.0</td>\n",
       "      <td>200192637.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>278</th>\n",
       "      <td>2014-04-05</td>\n",
       "      <td>202336542.0</td>\n",
       "      <td>163199682.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>183 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt\n",
       "274  2014-04-01         453320585.0       277429358.0\n",
       "275  2014-04-02         355347118.0       272612066.0\n",
       "276  2014-04-03         363877120.0       266605457.0\n",
       "277  2014-04-04         251895894.0       200192637.0\n",
       "278  2014-04-05         202336542.0       163199682.0\n",
       "..          ...                 ...               ...\n",
       "25   2014-09-26                 NaN               NaN\n",
       "26   2014-09-27                 NaN               NaN\n",
       "27   2014-09-28                 NaN               NaN\n",
       "28   2014-09-29                 NaN               NaN\n",
       "29   2014-09-30                 NaN               NaN\n",
       "\n",
       "[183 rows x 3 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#生成测试数据\n",
    "def generate_test_data(data):\n",
    "    #在copy数据上进行操作 要不是数据就发生改变了\n",
    "    total_balance=data.copy()\n",
    "    #生成2014-09-01到2014-09-30数据\n",
    "    start=datetime.datetime(2014,9,1)#这里要导包 datetime\n",
    "    end=datetime.datetime(2014,10,1) #因为下面用的while循环  所以这里不写成9-30  而是写成10-1\n",
    "    testdata=[]#这里先造一个空的列表  下面装数据\n",
    "    while start!=end:#当起始的时间不等于结束的时间的时候\n",
    "        #添加3个字段,date,total_purchase_amt,total_redeem_amt，后两个是空值  因为是我们要预测的数据\n",
    "        temp=[start,np.nan,np.nan]\n",
    "        testdata.append(temp)#把包含了三个字段（其实这个时候 只有start是有值的 另外两货是空值 ）添加到testdata里面去 然后日期+1\n",
    "        #日期+1\n",
    "        start+=datetime.timedelta(days=1) #这个while循环结束了  就有了一个大的列表 testdata 里面的每一个小元素又是一个含有三个元素的小列表\n",
    "    #封装 testdata成dataframe    \n",
    "    testdata=pd.DataFrame(testdata)    \n",
    "    testdata.columns= total_balance.columns#用上面total_balance的列索引\n",
    "    #将testdata合并到total_balance中 用concat操作  按照行拼接 就是在原数据的下面进行拼接\n",
    "    total_balance=pd.concat([total_balance,testdata],axis=0)\n",
    "    return total_balance\n",
    "\n",
    "total_balance=generate_test_data(total_balance)\n",
    "total_balance#原来是153行 现在是183行 在原来的基础上 按照指定的时间往下拼接了一部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>425</th>\n",
       "      <td>2014-08-30</td>\n",
       "      <td>199708772.0</td>\n",
       "      <td>196374134.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>426</th>\n",
       "      <td>2014-08-31</td>\n",
       "      <td>275090213.0</td>\n",
       "      <td>292943033.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt\n",
       "425  2014-08-30         199708772.0       196374134.0\n",
       "426  2014-08-31         275090213.0       292943033.0\n",
       "0    2014-09-01                 NaN               NaN\n",
       "1    2014-09-02                 NaN               NaN\n",
       "2    2014-09-03                 NaN               NaN\n",
       "3    2014-09-04                 NaN               NaN\n",
       "4    2014-09-05                 NaN               NaN\n",
       "5    2014-09-06                 NaN               NaN\n",
       "6    2014-09-07                 NaN               NaN\n",
       "7    2014-09-08                 NaN               NaN\n",
       "8    2014-09-09                 NaN               NaN\n",
       "9    2014-09-10                 NaN               NaN\n",
       "10   2014-09-11                 NaN               NaN\n",
       "11   2014-09-12                 NaN               NaN\n",
       "12   2014-09-13                 NaN               NaN\n",
       "13   2014-09-14                 NaN               NaN\n",
       "14   2014-09-15                 NaN               NaN\n",
       "15   2014-09-16                 NaN               NaN\n",
       "16   2014-09-17                 NaN               NaN\n",
       "17   2014-09-18                 NaN               NaN\n",
       "18   2014-09-19                 NaN               NaN\n",
       "19   2014-09-20                 NaN               NaN\n",
       "20   2014-09-21                 NaN               NaN\n",
       "21   2014-09-22                 NaN               NaN\n",
       "22   2014-09-23                 NaN               NaN\n",
       "23   2014-09-24                 NaN               NaN\n",
       "24   2014-09-25                 NaN               NaN\n",
       "25   2014-09-26                 NaN               NaN\n",
       "26   2014-09-27                 NaN               NaN\n",
       "27   2014-09-28                 NaN               NaN\n",
       "28   2014-09-29                 NaN               NaN\n",
       "29   2014-09-30                 NaN               NaN"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_balance.iloc[-32:,:]#这个时候就拿到了 最后32列 跟预期的一样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:9: FutureWarning: Series.dt.weekofyear and Series.dt.week have been deprecated.  Please use Series.dt.isocalendar().week instead.\n",
      "  if __name__ == '__main__':\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>day</th>\n",
       "      <th>month</th>\n",
       "      <th>year</th>\n",
       "      <th>week</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>2014-04-01</td>\n",
       "      <td>453320585.0</td>\n",
       "      <td>277429358.0</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>2014-04-02</td>\n",
       "      <td>355347118.0</td>\n",
       "      <td>272612066.0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>2014-04-03</td>\n",
       "      <td>363877120.0</td>\n",
       "      <td>266605457.0</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>277</th>\n",
       "      <td>2014-04-04</td>\n",
       "      <td>251895894.0</td>\n",
       "      <td>200192637.0</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>278</th>\n",
       "      <td>2014-04-05</td>\n",
       "      <td>202336542.0</td>\n",
       "      <td>163199682.0</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>27</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>28</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>183 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt  day  month  year  week  \\\n",
       "274  2014-04-01         453320585.0       277429358.0    1      4  2014    14   \n",
       "275  2014-04-02         355347118.0       272612066.0    2      4  2014    14   \n",
       "276  2014-04-03         363877120.0       266605457.0    3      4  2014    14   \n",
       "277  2014-04-04         251895894.0       200192637.0    4      4  2014    14   \n",
       "278  2014-04-05         202336542.0       163199682.0    5      4  2014    14   \n",
       "..          ...                 ...               ...  ...    ...   ...   ...   \n",
       "25   2014-09-26                 NaN               NaN   26      9  2014    39   \n",
       "26   2014-09-27                 NaN               NaN   27      9  2014    39   \n",
       "27   2014-09-28                 NaN               NaN   28      9  2014    39   \n",
       "28   2014-09-29                 NaN               NaN   29      9  2014    40   \n",
       "29   2014-09-30                 NaN               NaN   30      9  2014    40   \n",
       "\n",
       "     weekday  \n",
       "274        1  \n",
       "275        2  \n",
       "276        3  \n",
       "277        4  \n",
       "278        5  \n",
       "..       ...  \n",
       "25         4  \n",
       "26         5  \n",
       "27         6  \n",
       "28         0  \n",
       "29         1  \n",
       "\n",
       "[183 rows x 8 columns]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对total_balance添加时间维度 用上面已经写好的那个 add_timestamp（）函数\n",
    "total_balance=add_timestamp(total_balance)\n",
    "total_balance#这样就好了  可以看到 4月2号是周三  是第14个星期 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>day</th>\n",
       "      <th>month</th>\n",
       "      <th>year</th>\n",
       "      <th>week</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>2014-04-01</td>\n",
       "      <td>453320585.0</td>\n",
       "      <td>277429358.0</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>2014-04-02</td>\n",
       "      <td>355347118.0</td>\n",
       "      <td>272612066.0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>2014-04-03</td>\n",
       "      <td>363877120.0</td>\n",
       "      <td>266605457.0</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>277</th>\n",
       "      <td>2014-04-04</td>\n",
       "      <td>251895894.0</td>\n",
       "      <td>200192637.0</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>278</th>\n",
       "      <td>2014-04-05</td>\n",
       "      <td>202336542.0</td>\n",
       "      <td>163199682.0</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>27</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>28</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>183 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt  day  month  year  week  \\\n",
       "274  2014-04-01         453320585.0       277429358.0    1      4  2014    14   \n",
       "275  2014-04-02         355347118.0       272612066.0    2      4  2014    14   \n",
       "276  2014-04-03         363877120.0       266605457.0    3      4  2014    14   \n",
       "277  2014-04-04         251895894.0       200192637.0    4      4  2014    14   \n",
       "278  2014-04-05         202336542.0       163199682.0    5      4  2014    14   \n",
       "..          ...                 ...               ...  ...    ...   ...   ...   \n",
       "25   2014-09-26                 NaN               NaN   26      9  2014    39   \n",
       "26   2014-09-27                 NaN               NaN   27      9  2014    39   \n",
       "27   2014-09-28                 NaN               NaN   28      9  2014    39   \n",
       "28   2014-09-29                 NaN               NaN   29      9  2014    40   \n",
       "29   2014-09-30                 NaN               NaN   30      9  2014    40   \n",
       "\n",
       "     weekday  \n",
       "274        1  \n",
       "275        2  \n",
       "276        3  \n",
       "277        4  \n",
       "278        5  \n",
       "..       ...  \n",
       "25         4  \n",
       "26         5  \n",
       "27         6  \n",
       "28         0  \n",
       "29         1  \n",
       "\n",
       "[183 rows x 8 columns]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#存储备份total_balance为temp\n",
    "temp=total_balance.copy()\n",
    "temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>day</th>\n",
       "      <th>month</th>\n",
       "      <th>year</th>\n",
       "      <th>week</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>2014-04-01</td>\n",
       "      <td>453320585.0</td>\n",
       "      <td>277429358.0</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>2014-04-02</td>\n",
       "      <td>355347118.0</td>\n",
       "      <td>272612066.0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>2014-04-03</td>\n",
       "      <td>363877120.0</td>\n",
       "      <td>266605457.0</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>277</th>\n",
       "      <td>2014-04-04</td>\n",
       "      <td>251895894.0</td>\n",
       "      <td>200192637.0</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>278</th>\n",
       "      <td>2014-04-05</td>\n",
       "      <td>202336542.0</td>\n",
       "      <td>163199682.0</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>27</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>28</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>183 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt  day  month  year  week  \\\n",
       "274  2014-04-01         453320585.0       277429358.0    1      4  2014    14   \n",
       "275  2014-04-02         355347118.0       272612066.0    2      4  2014    14   \n",
       "276  2014-04-03         363877120.0       266605457.0    3      4  2014    14   \n",
       "277  2014-04-04         251895894.0       200192637.0    4      4  2014    14   \n",
       "278  2014-04-05         202336542.0       163199682.0    5      4  2014    14   \n",
       "..          ...                 ...               ...  ...    ...   ...   ...   \n",
       "25   2014-09-26                 NaN               NaN   26      9  2014    39   \n",
       "26   2014-09-27                 NaN               NaN   27      9  2014    39   \n",
       "27   2014-09-28                 NaN               NaN   28      9  2014    39   \n",
       "28   2014-09-29                 NaN               NaN   29      9  2014    40   \n",
       "29   2014-09-30                 NaN               NaN   30      9  2014    40   \n",
       "\n",
       "     weekday  \n",
       "274        1  \n",
       "275        2  \n",
       "276        3  \n",
       "277        4  \n",
       "278        5  \n",
       "..       ...  \n",
       "25         4  \n",
       "26         5  \n",
       "27         6  \n",
       "28         0  \n",
       "29         1  \n",
       "\n",
       "[183 rows x 8 columns]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#就算total_balance发生了改变  上面还是有备份temp的  \n",
    "total_balance=temp.copy()\n",
    "total_balance#这样就可以放心大胆的对total_balance操作了 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3RuleBased模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.1计算周期因子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>weekday</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3.075183e+08</td>\n",
       "      <td>3.268733e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>3.173125e+08</td>\n",
       "      <td>3.138971e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>3.133103e+08</td>\n",
       "      <td>3.076354e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>3.019386e+08</td>\n",
       "      <td>2.763898e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>2.398712e+08</td>\n",
       "      <td>2.591565e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>1.837682e+08</td>\n",
       "      <td>1.855464e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>1.884616e+08</td>\n",
       "      <td>1.980553e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   weekday  total_purchase_amt  total_redeem_amt\n",
       "0        0        3.075183e+08      3.268733e+08\n",
       "1        1        3.173125e+08      3.138971e+08\n",
       "2        2        3.133103e+08      3.076354e+08\n",
       "3        3        3.019386e+08      2.763898e+08\n",
       "4        4        2.398712e+08      2.591565e+08\n",
       "5        5        1.837682e+08      1.855464e+08\n",
       "6        6        1.884616e+08      1.980553e+08"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#下一步要 计算周期因子   total_balance只提取其中的三列  然后按照weekday聚合 然后求均值  然后就得到了 星期几的均值\n",
    "weekday_weight=total_balance[['weekday','total_purchase_amt','total_redeem_amt']].groupby('weekday',as_index=False).mean()\n",
    "weekday_weight#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3.075183e+08</td>\n",
       "      <td>3.268733e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>3.173125e+08</td>\n",
       "      <td>3.138971e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>3.133103e+08</td>\n",
       "      <td>3.076354e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>3.019386e+08</td>\n",
       "      <td>2.763898e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>2.398712e+08</td>\n",
       "      <td>2.591565e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>1.837682e+08</td>\n",
       "      <td>1.855464e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>1.884616e+08</td>\n",
       "      <td>1.980553e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   weekday  purchase_weekday  redeem_weekday\n",
       "0        0      3.075183e+08    3.268733e+08\n",
       "1        1      3.173125e+08    3.138971e+08\n",
       "2        2      3.133103e+08    3.076354e+08\n",
       "3        3      3.019386e+08    2.763898e+08\n",
       "4        4      2.398712e+08    2.591565e+08\n",
       "5        5      1.837682e+08    1.855464e+08\n",
       "6        6      1.884616e+08    1.980553e+08"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#把列索引的名称改一下\n",
    "weekday_weight=weekday_weight.rename(columns={'total_purchase_amt':'purchase_weekday','total_redeem_amt':'redeem_weekday'})\n",
    "weekday_weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   weekday  purchase_weekday  redeem_weekday\n",
       "0        0          1.163446        1.226999\n",
       "1        1          1.200501        1.178289\n",
       "2        2          1.185360        1.154784\n",
       "3        3          1.142336        1.037496\n",
       "4        4          0.907514        0.972807\n",
       "5        5          0.695258        0.696494\n",
       "6        6          0.713014        0.743449"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#purchase_weekday 是星期几的均值 然后除以total_balance中[total_purchase_amt]整体均值 就得到了 purchase_weekday的周期因子\n",
    "weekday_weight['purchase_weekday']/=np.mean(total_balance['total_purchase_amt'])\n",
    "#同理可以获得redeem_weekday的均值\n",
    "weekday_weight['redeem_weekday']/=np.mean(total_balance['total_redeem_amt'])\n",
    "weekday_weight#这样就得到了周期因子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>day</th>\n",
       "      <th>month</th>\n",
       "      <th>year</th>\n",
       "      <th>week</th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2014-04-01</td>\n",
       "      <td>453320585.0</td>\n",
       "      <td>277429358.0</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2014-04-02</td>\n",
       "      <td>355347118.0</td>\n",
       "      <td>272612066.0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2014-04-03</td>\n",
       "      <td>363877120.0</td>\n",
       "      <td>266605457.0</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>3</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2014-04-04</td>\n",
       "      <td>251895894.0</td>\n",
       "      <td>200192637.0</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>4</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014-04-05</td>\n",
       "      <td>202336542.0</td>\n",
       "      <td>163199682.0</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>2014</td>\n",
       "      <td>14</td>\n",
       "      <td>5</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>4</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>27</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>5</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>180</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>28</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>1</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>183 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt  day  month  year  week  \\\n",
       "0    2014-04-01         453320585.0       277429358.0    1      4  2014    14   \n",
       "1    2014-04-02         355347118.0       272612066.0    2      4  2014    14   \n",
       "2    2014-04-03         363877120.0       266605457.0    3      4  2014    14   \n",
       "3    2014-04-04         251895894.0       200192637.0    4      4  2014    14   \n",
       "4    2014-04-05         202336542.0       163199682.0    5      4  2014    14   \n",
       "..          ...                 ...               ...  ...    ...   ...   ...   \n",
       "178  2014-09-26                 NaN               NaN   26      9  2014    39   \n",
       "179  2014-09-27                 NaN               NaN   27      9  2014    39   \n",
       "180  2014-09-28                 NaN               NaN   28      9  2014    39   \n",
       "181  2014-09-29                 NaN               NaN   29      9  2014    40   \n",
       "182  2014-09-30                 NaN               NaN   30      9  2014    40   \n",
       "\n",
       "     weekday  purchase_weekday  redeem_weekday  \n",
       "0          1          1.200501        1.178289  \n",
       "1          2          1.185360        1.154784  \n",
       "2          3          1.142336        1.037496  \n",
       "3          4          0.907514        0.972807  \n",
       "4          5          0.695258        0.696494  \n",
       "..       ...               ...             ...  \n",
       "178        4          0.907514        0.972807  \n",
       "179        5          0.695258        0.696494  \n",
       "180        6          0.713014        0.743449  \n",
       "181        0          1.163446        1.226999  \n",
       "182        1          1.200501        1.178289  \n",
       "\n",
       "[183 rows x 10 columns]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#把得到的周期因子 拼接到原来的total_balance上去  按照weekday字段合并  然后按照左连接的方式\n",
    "total_balance=pd.merge(total_balance,weekday_weight,on='weekday',how='left')\n",
    "total_balance"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.2统计频次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>report_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>30</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>30</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>31</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>31</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>31</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>153 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     day  weekday  report_date\n",
       "0      1        0            1\n",
       "1      1        1            2\n",
       "2      1        3            1\n",
       "3      1        4            1\n",
       "4      1        6            1\n",
       "..   ...      ...          ...\n",
       "148   30        4            1\n",
       "149   30        5            1\n",
       "150   31        3            1\n",
       "151   31        5            1\n",
       "152   31        6            1\n",
       "\n",
       "[153 rows x 3 columns]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#计算日期的因子\n",
    "#统计周一到周日，1-30号中出现的频次['weekday','day']出现的频次  比如周一出现了几次   \n",
    "#提取'report_date','day','weekday'这三列  然后按照day','weekday'聚合  \n",
    "weekday_count=total_balance[['report_date','day','weekday']].groupby(['day','weekday'],as_index=False).count()\n",
    "weekday_count#这样就统计出来了 某一天日期 比如一号   在星期一出现了1次  星期2出现了2次 在星期4出现了1次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>report_date</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>26</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>27</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>28</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>30</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>31</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>153 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     day  weekday  report_date  purchase_weekday  redeem_weekday\n",
       "0      1        0            1          1.163446        1.226999\n",
       "1      2        0            1          1.163446        1.226999\n",
       "2      4        0            1          1.163446        1.226999\n",
       "3      5        0            1          1.163446        1.226999\n",
       "4      7        0            2          1.163446        1.226999\n",
       "..   ...      ...          ...               ...             ...\n",
       "148   26        5            2          0.695258        0.696494\n",
       "149   27        5            1          0.695258        0.696494\n",
       "150   28        5            1          0.695258        0.696494\n",
       "151   30        5            1          0.695258        0.696494\n",
       "152   31        5            1          0.695258        0.696494\n",
       "\n",
       "[153 rows x 5 columns]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#把weekday_count和上面的weekday_weight合并一下  按照weekday字段合并\n",
    "weekday_count=pd.merge(weekday_count,weekday_weight,on='weekday')\n",
    "weekday_count   #第一行数据表示：1号在星期1出现了一次 周一的puchase的影响影子是 1.163446   redeem_weekday影响影子是1.226999\n",
    "#最后一行数据表示  31号在周六出现了1次 周六的puchase的影响影子是 0.695258   redeem_weekday影响影子是0.696494"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(total_balance['month'])#这样就可以算出 total_balance里面的月份"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3按照rule_based方式计算预测结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>report_date</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.387815</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>26</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>0.231753</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>27</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>28</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>30</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>31</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>153 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     day  weekday  report_date  purchase_weekday  redeem_weekday\n",
       "0      1        0            1          0.193908        1.226999\n",
       "1      2        0            1          0.193908        1.226999\n",
       "2      4        0            1          0.193908        1.226999\n",
       "3      5        0            1          0.193908        1.226999\n",
       "4      7        0            2          0.387815        1.226999\n",
       "..   ...      ...          ...               ...             ...\n",
       "148   26        5            2          0.231753        0.696494\n",
       "149   27        5            1          0.115876        0.696494\n",
       "150   28        5            1          0.115876        0.696494\n",
       "151   30        5            1          0.115876        0.696494\n",
       "152   31        5            1          0.115876        0.696494\n",
       "\n",
       "[153 rows x 5 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#日期计算=周期因子*（周一到周日在1-31号中出现的频次）/一共有几个月\n",
    "#周期因子*次数/长度\n",
    "weekday_count['purchase_weekday']=weekday_count['purchase_weekday']*weekday_count['report_date']/len(np.unique(total_balance['month']))\n",
    "weekday_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>report_date</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>0.204500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>0.204500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>0.204500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>0.204500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.387815</td>\n",
       "      <td>0.409000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>26</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>0.231753</td>\n",
       "      <td>0.232165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>27</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.116082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>28</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.116082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>30</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.116082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>31</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.116082</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>153 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     day  weekday  report_date  purchase_weekday  redeem_weekday\n",
       "0      1        0            1          0.193908        0.204500\n",
       "1      2        0            1          0.193908        0.204500\n",
       "2      4        0            1          0.193908        0.204500\n",
       "3      5        0            1          0.193908        0.204500\n",
       "4      7        0            2          0.387815        0.409000\n",
       "..   ...      ...          ...               ...             ...\n",
       "148   26        5            2          0.231753        0.232165\n",
       "149   27        5            1          0.115876        0.116082\n",
       "150   28        5            1          0.115876        0.116082\n",
       "151   30        5            1          0.115876        0.116082\n",
       "152   31        5            1          0.115876        0.116082\n",
       "\n",
       "[153 rows x 5 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weekday_count['redeem_weekday']=weekday_count['redeem_weekday']*weekday_count['report_date']/len(np.unique(total_balance['month']))\n",
    "weekday_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>0.204500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>0.204500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>0.204500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>0.193908</td>\n",
       "      <td>0.204500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>0.387815</td>\n",
       "      <td>0.409000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>26</td>\n",
       "      <td>0.231753</td>\n",
       "      <td>0.232165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>27</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.116082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>28</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.116082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>30</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.116082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>31</td>\n",
       "      <td>0.115876</td>\n",
       "      <td>0.116082</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>153 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     day  purchase_weekday  redeem_weekday\n",
       "0      1          0.193908        0.204500\n",
       "1      2          0.193908        0.204500\n",
       "2      4          0.193908        0.204500\n",
       "3      5          0.193908        0.204500\n",
       "4      7          0.387815        0.409000\n",
       "..   ...               ...             ...\n",
       "148   26          0.231753        0.232165\n",
       "149   27          0.115876        0.116082\n",
       "150   28          0.115876        0.116082\n",
       "151   30          0.115876        0.116082\n",
       "152   31          0.115876        0.116082\n",
       "\n",
       "[153 rows x 3 columns]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=weekday_count.drop(['weekday','report_date'],axis=1)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>0.425101</td>\n",
       "      <td>0.412906</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  purchase_weekday  redeem_weekday\n",
       "0     1          1.054552        1.056222\n",
       "1     2          1.056240        1.064026\n",
       "2     3          1.013134        0.974668\n",
       "3     4          1.003197        1.018057\n",
       "4     5          0.967386        0.968096\n",
       "5     6          0.902444        0.914879\n",
       "6     7          1.010477        1.014370\n",
       "7     8          1.054552        1.056222\n",
       "8     9          1.056240        1.064026\n",
       "9    10          1.013134        0.974668\n",
       "10   11          1.003197        1.018057\n",
       "11   12          0.967386        0.968096\n",
       "12   13          0.902444        0.914879\n",
       "13   14          1.010477        1.014370\n",
       "14   15          1.054552        1.056222\n",
       "15   16          1.056240        1.064026\n",
       "16   17          1.013134        0.974668\n",
       "17   18          1.003197        1.018057\n",
       "18   19          0.967386        0.968096\n",
       "19   20          0.902444        0.914879\n",
       "20   21          1.010477        1.014370\n",
       "21   22          1.054552        1.056222\n",
       "22   23          1.056240        1.064026\n",
       "23   24          1.013134        0.974668\n",
       "24   25          1.003197        1.018057\n",
       "25   26          0.967386        0.968096\n",
       "26   27          0.902444        0.914879\n",
       "27   28          1.010477        1.014370\n",
       "28   29          1.054552        1.056222\n",
       "29   30          1.056240        1.064026\n",
       "30   31          0.425101        0.412906"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#['weekday','report_date']这两行不要了  然后按照 day 来聚合一下   得到了日期因子 累加和\n",
    "day_rate=weekday_count.drop(['weekday','report_date'],axis=1).groupby('day',as_index=False).sum()\n",
    "day_rate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.178338e+08</td>\n",
       "      <td>2.394654e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.425101e+08</td>\n",
       "      <td>2.130890e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.583158e+08</td>\n",
       "      <td>2.535862e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2.743470e+08</td>\n",
       "      <td>3.009591e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.034936e+08</td>\n",
       "      <td>2.644835e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2.474568e+08</td>\n",
       "      <td>2.466850e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.643790e+08</td>\n",
       "      <td>2.267630e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>3.015848e+08</td>\n",
       "      <td>2.689660e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.938419e+08</td>\n",
       "      <td>2.515698e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.140940e+08</td>\n",
       "      <td>2.496543e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.576274e+08</td>\n",
       "      <td>2.669609e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.542508e+08</td>\n",
       "      <td>2.225105e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.283210e+08</td>\n",
       "      <td>2.654175e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.618805e+08</td>\n",
       "      <td>2.917643e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.974980e+08</td>\n",
       "      <td>2.276925e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.234147e+08</td>\n",
       "      <td>2.968699e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.400234e+08</td>\n",
       "      <td>2.703199e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.492883e+08</td>\n",
       "      <td>2.538307e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.686273e+08</td>\n",
       "      <td>2.271034e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>2.763251e+08</td>\n",
       "      <td>2.169194e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.813571e+08</td>\n",
       "      <td>2.862035e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.532933e+08</td>\n",
       "      <td>2.859194e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.404650e+08</td>\n",
       "      <td>2.777964e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.262246e+08</td>\n",
       "      <td>2.692241e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.287499e+08</td>\n",
       "      <td>3.162706e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.458715e+08</td>\n",
       "      <td>2.839409e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.327543e+08</td>\n",
       "      <td>3.096201e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.743488e+08</td>\n",
       "      <td>3.341795e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.611213e+08</td>\n",
       "      <td>2.919627e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.460638e+08</td>\n",
       "      <td>2.995356e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>2.045476e+08</td>\n",
       "      <td>2.376665e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt\n",
       "0     1        3.178338e+08      2.394654e+08\n",
       "1     2        2.425101e+08      2.130890e+08\n",
       "2     3        2.583158e+08      2.535862e+08\n",
       "3     4        2.743470e+08      3.009591e+08\n",
       "4     5        3.034936e+08      2.644835e+08\n",
       "5     6        2.474568e+08      2.466850e+08\n",
       "6     7        2.643790e+08      2.267630e+08\n",
       "7     8        3.015848e+08      2.689660e+08\n",
       "8     9        2.938419e+08      2.515698e+08\n",
       "9    10        3.140940e+08      2.496543e+08\n",
       "10   11        2.576274e+08      2.669609e+08\n",
       "11   12        2.542508e+08      2.225105e+08\n",
       "12   13        2.283210e+08      2.654175e+08\n",
       "13   14        2.618805e+08      2.917643e+08\n",
       "14   15        2.974980e+08      2.276925e+08\n",
       "15   16        3.234147e+08      2.968699e+08\n",
       "16   17        2.400234e+08      2.703199e+08\n",
       "17   18        2.492883e+08      2.538307e+08\n",
       "18   19        2.686273e+08      2.271034e+08\n",
       "19   20        2.763251e+08      2.169194e+08\n",
       "20   21        2.813571e+08      2.862035e+08\n",
       "21   22        2.532933e+08      2.859194e+08\n",
       "22   23        2.404650e+08      2.777964e+08\n",
       "23   24        2.262246e+08      2.692241e+08\n",
       "24   25        2.287499e+08      3.162706e+08\n",
       "25   26        2.458715e+08      2.839409e+08\n",
       "26   27        2.327543e+08      3.096201e+08\n",
       "27   28        2.743488e+08      3.341795e+08\n",
       "28   29        2.611213e+08      2.919627e+08\n",
       "29   30        2.460638e+08      2.995356e+08\n",
       "30   31        2.045476e+08      2.376665e+08"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#按照日期day 计算均值，即1号的均值，2号的均值....\n",
    "day_mean=total_balance[['day','total_purchase_amt','total_redeem_amt']].groupby('day',as_index=False).mean()\n",
    "day_mean#每个月影响因子的均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.178338e+08</td>\n",
       "      <td>2.394654e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.425101e+08</td>\n",
       "      <td>2.130890e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.583158e+08</td>\n",
       "      <td>2.535862e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2.743470e+08</td>\n",
       "      <td>3.009591e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.034936e+08</td>\n",
       "      <td>2.644835e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2.474568e+08</td>\n",
       "      <td>2.466850e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.643790e+08</td>\n",
       "      <td>2.267630e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>3.015848e+08</td>\n",
       "      <td>2.689660e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.938419e+08</td>\n",
       "      <td>2.515698e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.140940e+08</td>\n",
       "      <td>2.496543e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.576274e+08</td>\n",
       "      <td>2.669609e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.542508e+08</td>\n",
       "      <td>2.225105e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.283210e+08</td>\n",
       "      <td>2.654175e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.618805e+08</td>\n",
       "      <td>2.917643e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.974980e+08</td>\n",
       "      <td>2.276925e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.234147e+08</td>\n",
       "      <td>2.968699e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.400234e+08</td>\n",
       "      <td>2.703199e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.492883e+08</td>\n",
       "      <td>2.538307e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.686273e+08</td>\n",
       "      <td>2.271034e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>2.763251e+08</td>\n",
       "      <td>2.169194e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.813571e+08</td>\n",
       "      <td>2.862035e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.532933e+08</td>\n",
       "      <td>2.859194e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.404650e+08</td>\n",
       "      <td>2.777964e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.262246e+08</td>\n",
       "      <td>2.692241e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.287499e+08</td>\n",
       "      <td>3.162706e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.458715e+08</td>\n",
       "      <td>2.839409e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.327543e+08</td>\n",
       "      <td>3.096201e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.743488e+08</td>\n",
       "      <td>3.341795e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.611213e+08</td>\n",
       "      <td>2.919627e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.460638e+08</td>\n",
       "      <td>2.995356e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>2.045476e+08</td>\n",
       "      <td>2.376665e+08</td>\n",
       "      <td>0.425101</td>\n",
       "      <td>0.412906</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt  purchase_weekday  \\\n",
       "0     1        3.178338e+08      2.394654e+08          1.054552   \n",
       "1     2        2.425101e+08      2.130890e+08          1.056240   \n",
       "2     3        2.583158e+08      2.535862e+08          1.013134   \n",
       "3     4        2.743470e+08      3.009591e+08          1.003197   \n",
       "4     5        3.034936e+08      2.644835e+08          0.967386   \n",
       "5     6        2.474568e+08      2.466850e+08          0.902444   \n",
       "6     7        2.643790e+08      2.267630e+08          1.010477   \n",
       "7     8        3.015848e+08      2.689660e+08          1.054552   \n",
       "8     9        2.938419e+08      2.515698e+08          1.056240   \n",
       "9    10        3.140940e+08      2.496543e+08          1.013134   \n",
       "10   11        2.576274e+08      2.669609e+08          1.003197   \n",
       "11   12        2.542508e+08      2.225105e+08          0.967386   \n",
       "12   13        2.283210e+08      2.654175e+08          0.902444   \n",
       "13   14        2.618805e+08      2.917643e+08          1.010477   \n",
       "14   15        2.974980e+08      2.276925e+08          1.054552   \n",
       "15   16        3.234147e+08      2.968699e+08          1.056240   \n",
       "16   17        2.400234e+08      2.703199e+08          1.013134   \n",
       "17   18        2.492883e+08      2.538307e+08          1.003197   \n",
       "18   19        2.686273e+08      2.271034e+08          0.967386   \n",
       "19   20        2.763251e+08      2.169194e+08          0.902444   \n",
       "20   21        2.813571e+08      2.862035e+08          1.010477   \n",
       "21   22        2.532933e+08      2.859194e+08          1.054552   \n",
       "22   23        2.404650e+08      2.777964e+08          1.056240   \n",
       "23   24        2.262246e+08      2.692241e+08          1.013134   \n",
       "24   25        2.287499e+08      3.162706e+08          1.003197   \n",
       "25   26        2.458715e+08      2.839409e+08          0.967386   \n",
       "26   27        2.327543e+08      3.096201e+08          0.902444   \n",
       "27   28        2.743488e+08      3.341795e+08          1.010477   \n",
       "28   29        2.611213e+08      2.919627e+08          1.054552   \n",
       "29   30        2.460638e+08      2.995356e+08          1.056240   \n",
       "30   31        2.045476e+08      2.376665e+08          0.425101   \n",
       "\n",
       "    redeem_weekday  \n",
       "0         1.056222  \n",
       "1         1.064026  \n",
       "2         0.974668  \n",
       "3         1.018057  \n",
       "4         0.968096  \n",
       "5         0.914879  \n",
       "6         1.014370  \n",
       "7         1.056222  \n",
       "8         1.064026  \n",
       "9         0.974668  \n",
       "10        1.018057  \n",
       "11        0.968096  \n",
       "12        0.914879  \n",
       "13        1.014370  \n",
       "14        1.056222  \n",
       "15        1.064026  \n",
       "16        0.974668  \n",
       "17        1.018057  \n",
       "18        0.968096  \n",
       "19        0.914879  \n",
       "20        1.014370  \n",
       "21        1.056222  \n",
       "22        1.064026  \n",
       "23        0.974668  \n",
       "24        1.018057  \n",
       "25        0.968096  \n",
       "26        0.914879  \n",
       "27        1.014370  \n",
       "28        1.056222  \n",
       "29        1.064026  \n",
       "30        0.412906  "
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#把day_mean 和 day_rate合并一下\n",
    "day_pred=pd.merge(day_mean,day_rate,on='day',how='left')\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.013922e+08</td>\n",
       "      <td>2.267189e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.295976e+08</td>\n",
       "      <td>2.002666e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.549670e+08</td>\n",
       "      <td>2.601770e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2.734726e+08</td>\n",
       "      <td>2.956211e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.137256e+08</td>\n",
       "      <td>2.731996e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2.742075e+08</td>\n",
       "      <td>2.696368e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.616379e+08</td>\n",
       "      <td>2.235506e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2.859838e+08</td>\n",
       "      <td>2.546492e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.781962e+08</td>\n",
       "      <td>2.364320e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.100221e+08</td>\n",
       "      <td>2.561429e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.568062e+08</td>\n",
       "      <td>2.622259e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.628226e+08</td>\n",
       "      <td>2.298433e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.530030e+08</td>\n",
       "      <td>2.901123e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.591653e+08</td>\n",
       "      <td>2.876310e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.821084e+08</td>\n",
       "      <td>2.155727e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.061944e+08</td>\n",
       "      <td>2.790062e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.369117e+08</td>\n",
       "      <td>2.773456e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.484937e+08</td>\n",
       "      <td>2.493286e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.776838e+08</td>\n",
       "      <td>2.345875e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>3.061965e+08</td>\n",
       "      <td>2.371019e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.784400e+08</td>\n",
       "      <td>2.821490e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.401903e+08</td>\n",
       "      <td>2.707002e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.276614e+08</td>\n",
       "      <td>2.610804e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.232918e+08</td>\n",
       "      <td>2.762213e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.280208e+08</td>\n",
       "      <td>3.106610e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.541608e+08</td>\n",
       "      <td>2.932982e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.579156e+08</td>\n",
       "      <td>3.384275e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.715043e+08</td>\n",
       "      <td>3.294453e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.476134e+08</td>\n",
       "      <td>2.764218e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.329621e+08</td>\n",
       "      <td>2.815114e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>4.811737e+08</td>\n",
       "      <td>5.755940e+08</td>\n",
       "      <td>0.425101</td>\n",
       "      <td>0.412906</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt  purchase_weekday  \\\n",
       "0     1        3.013922e+08      2.267189e+08          1.054552   \n",
       "1     2        2.295976e+08      2.002666e+08          1.056240   \n",
       "2     3        2.549670e+08      2.601770e+08          1.013134   \n",
       "3     4        2.734726e+08      2.956211e+08          1.003197   \n",
       "4     5        3.137256e+08      2.731996e+08          0.967386   \n",
       "5     6        2.742075e+08      2.696368e+08          0.902444   \n",
       "6     7        2.616379e+08      2.235506e+08          1.010477   \n",
       "7     8        2.859838e+08      2.546492e+08          1.054552   \n",
       "8     9        2.781962e+08      2.364320e+08          1.056240   \n",
       "9    10        3.100221e+08      2.561429e+08          1.013134   \n",
       "10   11        2.568062e+08      2.622259e+08          1.003197   \n",
       "11   12        2.628226e+08      2.298433e+08          0.967386   \n",
       "12   13        2.530030e+08      2.901123e+08          0.902444   \n",
       "13   14        2.591653e+08      2.876310e+08          1.010477   \n",
       "14   15        2.821084e+08      2.155727e+08          1.054552   \n",
       "15   16        3.061944e+08      2.790062e+08          1.056240   \n",
       "16   17        2.369117e+08      2.773456e+08          1.013134   \n",
       "17   18        2.484937e+08      2.493286e+08          1.003197   \n",
       "18   19        2.776838e+08      2.345875e+08          0.967386   \n",
       "19   20        3.061965e+08      2.371019e+08          0.902444   \n",
       "20   21        2.784400e+08      2.821490e+08          1.010477   \n",
       "21   22        2.401903e+08      2.707002e+08          1.054552   \n",
       "22   23        2.276614e+08      2.610804e+08          1.056240   \n",
       "23   24        2.232918e+08      2.762213e+08          1.013134   \n",
       "24   25        2.280208e+08      3.106610e+08          1.003197   \n",
       "25   26        2.541608e+08      2.932982e+08          0.967386   \n",
       "26   27        2.579156e+08      3.384275e+08          0.902444   \n",
       "27   28        2.715043e+08      3.294453e+08          1.010477   \n",
       "28   29        2.476134e+08      2.764218e+08          1.054552   \n",
       "29   30        2.329621e+08      2.815114e+08          1.056240   \n",
       "30   31        4.811737e+08      5.755940e+08          0.425101   \n",
       "\n",
       "    redeem_weekday  \n",
       "0         1.056222  \n",
       "1         1.064026  \n",
       "2         0.974668  \n",
       "3         1.018057  \n",
       "4         0.968096  \n",
       "5         0.914879  \n",
       "6         1.014370  \n",
       "7         1.056222  \n",
       "8         1.064026  \n",
       "9         0.974668  \n",
       "10        1.018057  \n",
       "11        0.968096  \n",
       "12        0.914879  \n",
       "13        1.014370  \n",
       "14        1.056222  \n",
       "15        1.064026  \n",
       "16        0.974668  \n",
       "17        1.018057  \n",
       "18        0.968096  \n",
       "19        0.914879  \n",
       "20        1.014370  \n",
       "21        1.056222  \n",
       "22        1.064026  \n",
       "23        0.974668  \n",
       "24        1.018057  \n",
       "25        0.968096  \n",
       "26        0.914879  \n",
       "27        1.014370  \n",
       "28        1.056222  \n",
       "29        1.064026  \n",
       "30        0.412906  "
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#下面的计算就是得到了 puchase_base\n",
    "day_pred['total_purchase_amt']/=day_pred['purchase_weekday']\n",
    "day_pred['total_redeem_amt']/=day_pred['redeem_weekday']\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "      <th>report_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.013922e+08</td>\n",
       "      <td>2.267189e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.295976e+08</td>\n",
       "      <td>2.002666e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.549670e+08</td>\n",
       "      <td>2.601770e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "      <td>2014-09-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2.734726e+08</td>\n",
       "      <td>2.956211e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "      <td>2014-09-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.137256e+08</td>\n",
       "      <td>2.731996e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "      <td>2014-09-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2.742075e+08</td>\n",
       "      <td>2.696368e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "      <td>2014-09-06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.616379e+08</td>\n",
       "      <td>2.235506e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "      <td>2014-09-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2.859838e+08</td>\n",
       "      <td>2.546492e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.781962e+08</td>\n",
       "      <td>2.364320e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.100221e+08</td>\n",
       "      <td>2.561429e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "      <td>2014-09-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.568062e+08</td>\n",
       "      <td>2.622259e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "      <td>2014-09-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.628226e+08</td>\n",
       "      <td>2.298433e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "      <td>2014-09-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.530030e+08</td>\n",
       "      <td>2.901123e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "      <td>2014-09-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.591653e+08</td>\n",
       "      <td>2.876310e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "      <td>2014-09-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.821084e+08</td>\n",
       "      <td>2.155727e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.061944e+08</td>\n",
       "      <td>2.790062e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.369117e+08</td>\n",
       "      <td>2.773456e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "      <td>2014-09-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.484937e+08</td>\n",
       "      <td>2.493286e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "      <td>2014-09-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.776838e+08</td>\n",
       "      <td>2.345875e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "      <td>2014-09-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>3.061965e+08</td>\n",
       "      <td>2.371019e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "      <td>2014-09-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.784400e+08</td>\n",
       "      <td>2.821490e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "      <td>2014-09-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.401903e+08</td>\n",
       "      <td>2.707002e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.276614e+08</td>\n",
       "      <td>2.610804e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.232918e+08</td>\n",
       "      <td>2.762213e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "      <td>2014-09-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.280208e+08</td>\n",
       "      <td>3.106610e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "      <td>2014-09-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.541608e+08</td>\n",
       "      <td>2.932982e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "      <td>2014-09-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.579156e+08</td>\n",
       "      <td>3.384275e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "      <td>2014-09-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.715043e+08</td>\n",
       "      <td>3.294453e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "      <td>2014-09-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.476134e+08</td>\n",
       "      <td>2.764218e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.329621e+08</td>\n",
       "      <td>2.815114e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>4.811737e+08</td>\n",
       "      <td>5.755940e+08</td>\n",
       "      <td>0.425101</td>\n",
       "      <td>0.412906</td>\n",
       "      <td>NaT</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt  purchase_weekday  \\\n",
       "0     1        3.013922e+08      2.267189e+08          1.054552   \n",
       "1     2        2.295976e+08      2.002666e+08          1.056240   \n",
       "2     3        2.549670e+08      2.601770e+08          1.013134   \n",
       "3     4        2.734726e+08      2.956211e+08          1.003197   \n",
       "4     5        3.137256e+08      2.731996e+08          0.967386   \n",
       "5     6        2.742075e+08      2.696368e+08          0.902444   \n",
       "6     7        2.616379e+08      2.235506e+08          1.010477   \n",
       "7     8        2.859838e+08      2.546492e+08          1.054552   \n",
       "8     9        2.781962e+08      2.364320e+08          1.056240   \n",
       "9    10        3.100221e+08      2.561429e+08          1.013134   \n",
       "10   11        2.568062e+08      2.622259e+08          1.003197   \n",
       "11   12        2.628226e+08      2.298433e+08          0.967386   \n",
       "12   13        2.530030e+08      2.901123e+08          0.902444   \n",
       "13   14        2.591653e+08      2.876310e+08          1.010477   \n",
       "14   15        2.821084e+08      2.155727e+08          1.054552   \n",
       "15   16        3.061944e+08      2.790062e+08          1.056240   \n",
       "16   17        2.369117e+08      2.773456e+08          1.013134   \n",
       "17   18        2.484937e+08      2.493286e+08          1.003197   \n",
       "18   19        2.776838e+08      2.345875e+08          0.967386   \n",
       "19   20        3.061965e+08      2.371019e+08          0.902444   \n",
       "20   21        2.784400e+08      2.821490e+08          1.010477   \n",
       "21   22        2.401903e+08      2.707002e+08          1.054552   \n",
       "22   23        2.276614e+08      2.610804e+08          1.056240   \n",
       "23   24        2.232918e+08      2.762213e+08          1.013134   \n",
       "24   25        2.280208e+08      3.106610e+08          1.003197   \n",
       "25   26        2.541608e+08      2.932982e+08          0.967386   \n",
       "26   27        2.579156e+08      3.384275e+08          0.902444   \n",
       "27   28        2.715043e+08      3.294453e+08          1.010477   \n",
       "28   29        2.476134e+08      2.764218e+08          1.054552   \n",
       "29   30        2.329621e+08      2.815114e+08          1.056240   \n",
       "30   31        4.811737e+08      5.755940e+08          0.425101   \n",
       "\n",
       "    redeem_weekday report_date  \n",
       "0         1.056222  2014-09-01  \n",
       "1         1.064026  2014-09-02  \n",
       "2         0.974668  2014-09-03  \n",
       "3         1.018057  2014-09-04  \n",
       "4         0.968096  2014-09-05  \n",
       "5         0.914879  2014-09-06  \n",
       "6         1.014370  2014-09-07  \n",
       "7         1.056222  2014-09-08  \n",
       "8         1.064026  2014-09-09  \n",
       "9         0.974668  2014-09-10  \n",
       "10        1.018057  2014-09-11  \n",
       "11        0.968096  2014-09-12  \n",
       "12        0.914879  2014-09-13  \n",
       "13        1.014370  2014-09-14  \n",
       "14        1.056222  2014-09-15  \n",
       "15        1.064026  2014-09-16  \n",
       "16        0.974668  2014-09-17  \n",
       "17        1.018057  2014-09-18  \n",
       "18        0.968096  2014-09-19  \n",
       "19        0.914879  2014-09-20  \n",
       "20        1.014370  2014-09-21  \n",
       "21        1.056222  2014-09-22  \n",
       "22        1.064026  2014-09-23  \n",
       "23        0.974668  2014-09-24  \n",
       "24        1.018057  2014-09-25  \n",
       "25        0.968096  2014-09-26  \n",
       "26        0.914879  2014-09-27  \n",
       "27        1.014370  2014-09-28  \n",
       "28        1.056222  2014-09-29  \n",
       "29        1.064026  2014-09-30  \n",
       "30        0.412906         NaT  "
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#9月份是没有31号的 所以我们只想要30天\n",
    "for index,row in day_pred.iterrows():\n",
    "    if  row['day']==31:\n",
    "        break\n",
    "     #添加日期字段 report_date\n",
    "    day_pred.loc[index,'report_date']=pd.to_datetime('2014/09/'+str(int(row['day'])))\n",
    "day_pred  #31号的就没有了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "      <th>report_date</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.013922e+08</td>\n",
       "      <td>2.267189e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.295976e+08</td>\n",
       "      <td>2.002666e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.549670e+08</td>\n",
       "      <td>2.601770e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2.734726e+08</td>\n",
       "      <td>2.956211e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.137256e+08</td>\n",
       "      <td>2.731996e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2.742075e+08</td>\n",
       "      <td>2.696368e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.616379e+08</td>\n",
       "      <td>2.235506e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2.859838e+08</td>\n",
       "      <td>2.546492e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.781962e+08</td>\n",
       "      <td>2.364320e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.100221e+08</td>\n",
       "      <td>2.561429e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.568062e+08</td>\n",
       "      <td>2.622259e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.628226e+08</td>\n",
       "      <td>2.298433e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.530030e+08</td>\n",
       "      <td>2.901123e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.591653e+08</td>\n",
       "      <td>2.876310e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.821084e+08</td>\n",
       "      <td>2.155727e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.061944e+08</td>\n",
       "      <td>2.790062e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.369117e+08</td>\n",
       "      <td>2.773456e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.484937e+08</td>\n",
       "      <td>2.493286e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.776838e+08</td>\n",
       "      <td>2.345875e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>3.061965e+08</td>\n",
       "      <td>2.371019e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.784400e+08</td>\n",
       "      <td>2.821490e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.401903e+08</td>\n",
       "      <td>2.707002e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.276614e+08</td>\n",
       "      <td>2.610804e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.232918e+08</td>\n",
       "      <td>2.762213e+08</td>\n",
       "      <td>1.013134</td>\n",
       "      <td>0.974668</td>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.280208e+08</td>\n",
       "      <td>3.106610e+08</td>\n",
       "      <td>1.003197</td>\n",
       "      <td>1.018057</td>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.541608e+08</td>\n",
       "      <td>2.932982e+08</td>\n",
       "      <td>0.967386</td>\n",
       "      <td>0.968096</td>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.579156e+08</td>\n",
       "      <td>3.384275e+08</td>\n",
       "      <td>0.902444</td>\n",
       "      <td>0.914879</td>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.715043e+08</td>\n",
       "      <td>3.294453e+08</td>\n",
       "      <td>1.010477</td>\n",
       "      <td>1.014370</td>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.476134e+08</td>\n",
       "      <td>2.764218e+08</td>\n",
       "      <td>1.054552</td>\n",
       "      <td>1.056222</td>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.329621e+08</td>\n",
       "      <td>2.815114e+08</td>\n",
       "      <td>1.056240</td>\n",
       "      <td>1.064026</td>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>4.811737e+08</td>\n",
       "      <td>5.755940e+08</td>\n",
       "      <td>0.425101</td>\n",
       "      <td>0.412906</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt  purchase_weekday  \\\n",
       "0     1        3.013922e+08      2.267189e+08          1.054552   \n",
       "1     2        2.295976e+08      2.002666e+08          1.056240   \n",
       "2     3        2.549670e+08      2.601770e+08          1.013134   \n",
       "3     4        2.734726e+08      2.956211e+08          1.003197   \n",
       "4     5        3.137256e+08      2.731996e+08          0.967386   \n",
       "5     6        2.742075e+08      2.696368e+08          0.902444   \n",
       "6     7        2.616379e+08      2.235506e+08          1.010477   \n",
       "7     8        2.859838e+08      2.546492e+08          1.054552   \n",
       "8     9        2.781962e+08      2.364320e+08          1.056240   \n",
       "9    10        3.100221e+08      2.561429e+08          1.013134   \n",
       "10   11        2.568062e+08      2.622259e+08          1.003197   \n",
       "11   12        2.628226e+08      2.298433e+08          0.967386   \n",
       "12   13        2.530030e+08      2.901123e+08          0.902444   \n",
       "13   14        2.591653e+08      2.876310e+08          1.010477   \n",
       "14   15        2.821084e+08      2.155727e+08          1.054552   \n",
       "15   16        3.061944e+08      2.790062e+08          1.056240   \n",
       "16   17        2.369117e+08      2.773456e+08          1.013134   \n",
       "17   18        2.484937e+08      2.493286e+08          1.003197   \n",
       "18   19        2.776838e+08      2.345875e+08          0.967386   \n",
       "19   20        3.061965e+08      2.371019e+08          0.902444   \n",
       "20   21        2.784400e+08      2.821490e+08          1.010477   \n",
       "21   22        2.401903e+08      2.707002e+08          1.054552   \n",
       "22   23        2.276614e+08      2.610804e+08          1.056240   \n",
       "23   24        2.232918e+08      2.762213e+08          1.013134   \n",
       "24   25        2.280208e+08      3.106610e+08          1.003197   \n",
       "25   26        2.541608e+08      2.932982e+08          0.967386   \n",
       "26   27        2.579156e+08      3.384275e+08          0.902444   \n",
       "27   28        2.715043e+08      3.294453e+08          1.010477   \n",
       "28   29        2.476134e+08      2.764218e+08          1.054552   \n",
       "29   30        2.329621e+08      2.815114e+08          1.056240   \n",
       "30   31        4.811737e+08      5.755940e+08          0.425101   \n",
       "\n",
       "    redeem_weekday report_date  weekday  \n",
       "0         1.056222  2014-09-01      0.0  \n",
       "1         1.064026  2014-09-02      1.0  \n",
       "2         0.974668  2014-09-03      2.0  \n",
       "3         1.018057  2014-09-04      3.0  \n",
       "4         0.968096  2014-09-05      4.0  \n",
       "5         0.914879  2014-09-06      5.0  \n",
       "6         1.014370  2014-09-07      6.0  \n",
       "7         1.056222  2014-09-08      0.0  \n",
       "8         1.064026  2014-09-09      1.0  \n",
       "9         0.974668  2014-09-10      2.0  \n",
       "10        1.018057  2014-09-11      3.0  \n",
       "11        0.968096  2014-09-12      4.0  \n",
       "12        0.914879  2014-09-13      5.0  \n",
       "13        1.014370  2014-09-14      6.0  \n",
       "14        1.056222  2014-09-15      0.0  \n",
       "15        1.064026  2014-09-16      1.0  \n",
       "16        0.974668  2014-09-17      2.0  \n",
       "17        1.018057  2014-09-18      3.0  \n",
       "18        0.968096  2014-09-19      4.0  \n",
       "19        0.914879  2014-09-20      5.0  \n",
       "20        1.014370  2014-09-21      6.0  \n",
       "21        1.056222  2014-09-22      0.0  \n",
       "22        1.064026  2014-09-23      1.0  \n",
       "23        0.974668  2014-09-24      2.0  \n",
       "24        1.018057  2014-09-25      3.0  \n",
       "25        0.968096  2014-09-26      4.0  \n",
       "26        0.914879  2014-09-27      5.0  \n",
       "27        1.014370  2014-09-28      6.0  \n",
       "28        1.056222  2014-09-29      0.0  \n",
       "29        1.064026  2014-09-30      1.0  \n",
       "30        0.412906         NaT      NaN  "
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#利用周期因子，进行计算 base*周期因子=预测结果\n",
    "#先给day_pred数据添加上一个 weekday\n",
    "day_pred['weekday']=day_pred['report_date'].dt.weekday\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>report_date</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.013922e+08</td>\n",
       "      <td>2.267189e+08</td>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.295976e+08</td>\n",
       "      <td>2.002666e+08</td>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.549670e+08</td>\n",
       "      <td>2.601770e+08</td>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2.734726e+08</td>\n",
       "      <td>2.956211e+08</td>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.137256e+08</td>\n",
       "      <td>2.731996e+08</td>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2.742075e+08</td>\n",
       "      <td>2.696368e+08</td>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.616379e+08</td>\n",
       "      <td>2.235506e+08</td>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2.859838e+08</td>\n",
       "      <td>2.546492e+08</td>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.781962e+08</td>\n",
       "      <td>2.364320e+08</td>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.100221e+08</td>\n",
       "      <td>2.561429e+08</td>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.568062e+08</td>\n",
       "      <td>2.622259e+08</td>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.628226e+08</td>\n",
       "      <td>2.298433e+08</td>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.530030e+08</td>\n",
       "      <td>2.901123e+08</td>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.591653e+08</td>\n",
       "      <td>2.876310e+08</td>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.821084e+08</td>\n",
       "      <td>2.155727e+08</td>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.061944e+08</td>\n",
       "      <td>2.790062e+08</td>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.369117e+08</td>\n",
       "      <td>2.773456e+08</td>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.484937e+08</td>\n",
       "      <td>2.493286e+08</td>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.776838e+08</td>\n",
       "      <td>2.345875e+08</td>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>3.061965e+08</td>\n",
       "      <td>2.371019e+08</td>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.784400e+08</td>\n",
       "      <td>2.821490e+08</td>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.401903e+08</td>\n",
       "      <td>2.707002e+08</td>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.276614e+08</td>\n",
       "      <td>2.610804e+08</td>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.232918e+08</td>\n",
       "      <td>2.762213e+08</td>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.280208e+08</td>\n",
       "      <td>3.106610e+08</td>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.541608e+08</td>\n",
       "      <td>2.932982e+08</td>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.579156e+08</td>\n",
       "      <td>3.384275e+08</td>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.715043e+08</td>\n",
       "      <td>3.294453e+08</td>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.476134e+08</td>\n",
       "      <td>2.764218e+08</td>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.329621e+08</td>\n",
       "      <td>2.815114e+08</td>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>4.811737e+08</td>\n",
       "      <td>5.755940e+08</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt report_date  weekday\n",
       "0     1        3.013922e+08      2.267189e+08  2014-09-01      0.0\n",
       "1     2        2.295976e+08      2.002666e+08  2014-09-02      1.0\n",
       "2     3        2.549670e+08      2.601770e+08  2014-09-03      2.0\n",
       "3     4        2.734726e+08      2.956211e+08  2014-09-04      3.0\n",
       "4     5        3.137256e+08      2.731996e+08  2014-09-05      4.0\n",
       "5     6        2.742075e+08      2.696368e+08  2014-09-06      5.0\n",
       "6     7        2.616379e+08      2.235506e+08  2014-09-07      6.0\n",
       "7     8        2.859838e+08      2.546492e+08  2014-09-08      0.0\n",
       "8     9        2.781962e+08      2.364320e+08  2014-09-09      1.0\n",
       "9    10        3.100221e+08      2.561429e+08  2014-09-10      2.0\n",
       "10   11        2.568062e+08      2.622259e+08  2014-09-11      3.0\n",
       "11   12        2.628226e+08      2.298433e+08  2014-09-12      4.0\n",
       "12   13        2.530030e+08      2.901123e+08  2014-09-13      5.0\n",
       "13   14        2.591653e+08      2.876310e+08  2014-09-14      6.0\n",
       "14   15        2.821084e+08      2.155727e+08  2014-09-15      0.0\n",
       "15   16        3.061944e+08      2.790062e+08  2014-09-16      1.0\n",
       "16   17        2.369117e+08      2.773456e+08  2014-09-17      2.0\n",
       "17   18        2.484937e+08      2.493286e+08  2014-09-18      3.0\n",
       "18   19        2.776838e+08      2.345875e+08  2014-09-19      4.0\n",
       "19   20        3.061965e+08      2.371019e+08  2014-09-20      5.0\n",
       "20   21        2.784400e+08      2.821490e+08  2014-09-21      6.0\n",
       "21   22        2.401903e+08      2.707002e+08  2014-09-22      0.0\n",
       "22   23        2.276614e+08      2.610804e+08  2014-09-23      1.0\n",
       "23   24        2.232918e+08      2.762213e+08  2014-09-24      2.0\n",
       "24   25        2.280208e+08      3.106610e+08  2014-09-25      3.0\n",
       "25   26        2.541608e+08      2.932982e+08  2014-09-26      4.0\n",
       "26   27        2.579156e+08      3.384275e+08  2014-09-27      5.0\n",
       "27   28        2.715043e+08      3.294453e+08  2014-09-28      6.0\n",
       "28   29        2.476134e+08      2.764218e+08  2014-09-29      0.0\n",
       "29   30        2.329621e+08      2.815114e+08  2014-09-30      1.0\n",
       "30   31        4.811737e+08      5.755940e+08         NaT      NaN"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#purchase_weekday\tredeem_weekday这两列特征不要了\n",
    "day_pred=day_pred[['day','total_purchase_amt','total_redeem_amt','report_date','weekday']]\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   weekday  purchase_weekday  redeem_weekday\n",
       "0        0          1.163446        1.226999\n",
       "1        1          1.200501        1.178289\n",
       "2        2          1.185360        1.154784\n",
       "3        3          1.142336        1.037496\n",
       "4        4          0.907514        0.972807\n",
       "5        5          0.695258        0.696494\n",
       "6        6          0.713014        0.743449"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weekday_weight#下一步day_pred和weekday_weight再合并一下"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>report_date</th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.013922e+08</td>\n",
       "      <td>2.267189e+08</td>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>8</td>\n",
       "      <td>2.859838e+08</td>\n",
       "      <td>2.546492e+08</td>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>15</td>\n",
       "      <td>2.821084e+08</td>\n",
       "      <td>2.155727e+08</td>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>22</td>\n",
       "      <td>2.401903e+08</td>\n",
       "      <td>2.707002e+08</td>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>29</td>\n",
       "      <td>2.476134e+08</td>\n",
       "      <td>2.764218e+08</td>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2</td>\n",
       "      <td>2.295976e+08</td>\n",
       "      <td>2.002666e+08</td>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>2.781962e+08</td>\n",
       "      <td>2.364320e+08</td>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>16</td>\n",
       "      <td>3.061944e+08</td>\n",
       "      <td>2.790062e+08</td>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>23</td>\n",
       "      <td>2.276614e+08</td>\n",
       "      <td>2.610804e+08</td>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>30</td>\n",
       "      <td>2.329621e+08</td>\n",
       "      <td>2.815114e+08</td>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>3</td>\n",
       "      <td>2.549670e+08</td>\n",
       "      <td>2.601770e+08</td>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>10</td>\n",
       "      <td>3.100221e+08</td>\n",
       "      <td>2.561429e+08</td>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>17</td>\n",
       "      <td>2.369117e+08</td>\n",
       "      <td>2.773456e+08</td>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>24</td>\n",
       "      <td>2.232918e+08</td>\n",
       "      <td>2.762213e+08</td>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>4</td>\n",
       "      <td>2.734726e+08</td>\n",
       "      <td>2.956211e+08</td>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>11</td>\n",
       "      <td>2.568062e+08</td>\n",
       "      <td>2.622259e+08</td>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>18</td>\n",
       "      <td>2.484937e+08</td>\n",
       "      <td>2.493286e+08</td>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>25</td>\n",
       "      <td>2.280208e+08</td>\n",
       "      <td>3.106610e+08</td>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>5</td>\n",
       "      <td>3.137256e+08</td>\n",
       "      <td>2.731996e+08</td>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>12</td>\n",
       "      <td>2.628226e+08</td>\n",
       "      <td>2.298433e+08</td>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>19</td>\n",
       "      <td>2.776838e+08</td>\n",
       "      <td>2.345875e+08</td>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>26</td>\n",
       "      <td>2.541608e+08</td>\n",
       "      <td>2.932982e+08</td>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>6</td>\n",
       "      <td>2.742075e+08</td>\n",
       "      <td>2.696368e+08</td>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>13</td>\n",
       "      <td>2.530030e+08</td>\n",
       "      <td>2.901123e+08</td>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>20</td>\n",
       "      <td>3.061965e+08</td>\n",
       "      <td>2.371019e+08</td>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>27</td>\n",
       "      <td>2.579156e+08</td>\n",
       "      <td>3.384275e+08</td>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>7</td>\n",
       "      <td>2.616379e+08</td>\n",
       "      <td>2.235506e+08</td>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>14</td>\n",
       "      <td>2.591653e+08</td>\n",
       "      <td>2.876310e+08</td>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>21</td>\n",
       "      <td>2.784400e+08</td>\n",
       "      <td>2.821490e+08</td>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>28</td>\n",
       "      <td>2.715043e+08</td>\n",
       "      <td>3.294453e+08</td>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt report_date  weekday  \\\n",
       "0     1        3.013922e+08      2.267189e+08  2014-09-01      0.0   \n",
       "1     8        2.859838e+08      2.546492e+08  2014-09-08      0.0   \n",
       "2    15        2.821084e+08      2.155727e+08  2014-09-15      0.0   \n",
       "3    22        2.401903e+08      2.707002e+08  2014-09-22      0.0   \n",
       "4    29        2.476134e+08      2.764218e+08  2014-09-29      0.0   \n",
       "5     2        2.295976e+08      2.002666e+08  2014-09-02      1.0   \n",
       "6     9        2.781962e+08      2.364320e+08  2014-09-09      1.0   \n",
       "7    16        3.061944e+08      2.790062e+08  2014-09-16      1.0   \n",
       "8    23        2.276614e+08      2.610804e+08  2014-09-23      1.0   \n",
       "9    30        2.329621e+08      2.815114e+08  2014-09-30      1.0   \n",
       "10    3        2.549670e+08      2.601770e+08  2014-09-03      2.0   \n",
       "11   10        3.100221e+08      2.561429e+08  2014-09-10      2.0   \n",
       "12   17        2.369117e+08      2.773456e+08  2014-09-17      2.0   \n",
       "13   24        2.232918e+08      2.762213e+08  2014-09-24      2.0   \n",
       "14    4        2.734726e+08      2.956211e+08  2014-09-04      3.0   \n",
       "15   11        2.568062e+08      2.622259e+08  2014-09-11      3.0   \n",
       "16   18        2.484937e+08      2.493286e+08  2014-09-18      3.0   \n",
       "17   25        2.280208e+08      3.106610e+08  2014-09-25      3.0   \n",
       "18    5        3.137256e+08      2.731996e+08  2014-09-05      4.0   \n",
       "19   12        2.628226e+08      2.298433e+08  2014-09-12      4.0   \n",
       "20   19        2.776838e+08      2.345875e+08  2014-09-19      4.0   \n",
       "21   26        2.541608e+08      2.932982e+08  2014-09-26      4.0   \n",
       "22    6        2.742075e+08      2.696368e+08  2014-09-06      5.0   \n",
       "23   13        2.530030e+08      2.901123e+08  2014-09-13      5.0   \n",
       "24   20        3.061965e+08      2.371019e+08  2014-09-20      5.0   \n",
       "25   27        2.579156e+08      3.384275e+08  2014-09-27      5.0   \n",
       "26    7        2.616379e+08      2.235506e+08  2014-09-07      6.0   \n",
       "27   14        2.591653e+08      2.876310e+08  2014-09-14      6.0   \n",
       "28   21        2.784400e+08      2.821490e+08  2014-09-21      6.0   \n",
       "29   28        2.715043e+08      3.294453e+08  2014-09-28      6.0   \n",
       "\n",
       "    purchase_weekday  redeem_weekday  \n",
       "0           1.163446        1.226999  \n",
       "1           1.163446        1.226999  \n",
       "2           1.163446        1.226999  \n",
       "3           1.163446        1.226999  \n",
       "4           1.163446        1.226999  \n",
       "5           1.200501        1.178289  \n",
       "6           1.200501        1.178289  \n",
       "7           1.200501        1.178289  \n",
       "8           1.200501        1.178289  \n",
       "9           1.200501        1.178289  \n",
       "10          1.185360        1.154784  \n",
       "11          1.185360        1.154784  \n",
       "12          1.185360        1.154784  \n",
       "13          1.185360        1.154784  \n",
       "14          1.142336        1.037496  \n",
       "15          1.142336        1.037496  \n",
       "16          1.142336        1.037496  \n",
       "17          1.142336        1.037496  \n",
       "18          0.907514        0.972807  \n",
       "19          0.907514        0.972807  \n",
       "20          0.907514        0.972807  \n",
       "21          0.907514        0.972807  \n",
       "22          0.695258        0.696494  \n",
       "23          0.695258        0.696494  \n",
       "24          0.695258        0.696494  \n",
       "25          0.695258        0.696494  \n",
       "26          0.713014        0.743449  \n",
       "27          0.713014        0.743449  \n",
       "28          0.713014        0.743449  \n",
       "29          0.713014        0.743449  "
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#合并\n",
    "day_pred=pd.merge(day_pred,weekday_weight,on='weekday')\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>report_date</th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.506536e+08</td>\n",
       "      <td>2.781837e+08</td>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>8</td>\n",
       "      <td>3.327267e+08</td>\n",
       "      <td>3.124542e+08</td>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>15</td>\n",
       "      <td>3.282179e+08</td>\n",
       "      <td>2.645074e+08</td>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>22</td>\n",
       "      <td>2.794485e+08</td>\n",
       "      <td>3.321488e+08</td>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>29</td>\n",
       "      <td>2.880849e+08</td>\n",
       "      <td>3.391692e+08</td>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.163446</td>\n",
       "      <td>1.226999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2</td>\n",
       "      <td>2.756322e+08</td>\n",
       "      <td>2.359720e+08</td>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>3.339748e+08</td>\n",
       "      <td>2.785852e+08</td>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>16</td>\n",
       "      <td>3.675868e+08</td>\n",
       "      <td>3.287500e+08</td>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>23</td>\n",
       "      <td>2.733078e+08</td>\n",
       "      <td>3.076282e+08</td>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>30</td>\n",
       "      <td>2.796713e+08</td>\n",
       "      <td>3.317019e+08</td>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.200501</td>\n",
       "      <td>1.178289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>3</td>\n",
       "      <td>3.022276e+08</td>\n",
       "      <td>3.004483e+08</td>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>10</td>\n",
       "      <td>3.674877e+08</td>\n",
       "      <td>2.957898e+08</td>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>17</td>\n",
       "      <td>2.808256e+08</td>\n",
       "      <td>3.202744e+08</td>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>24</td>\n",
       "      <td>2.646811e+08</td>\n",
       "      <td>3.189761e+08</td>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.185360</td>\n",
       "      <td>1.154784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>4</td>\n",
       "      <td>3.123977e+08</td>\n",
       "      <td>3.067058e+08</td>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>11</td>\n",
       "      <td>2.933591e+08</td>\n",
       "      <td>2.720584e+08</td>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>18</td>\n",
       "      <td>2.838634e+08</td>\n",
       "      <td>2.586775e+08</td>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>25</td>\n",
       "      <td>2.604765e+08</td>\n",
       "      <td>3.223097e+08</td>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.142336</td>\n",
       "      <td>1.037496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>5</td>\n",
       "      <td>2.847104e+08</td>\n",
       "      <td>2.657704e+08</td>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>12</td>\n",
       "      <td>2.385152e+08</td>\n",
       "      <td>2.235932e+08</td>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>19</td>\n",
       "      <td>2.520020e+08</td>\n",
       "      <td>2.282084e+08</td>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>26</td>\n",
       "      <td>2.306545e+08</td>\n",
       "      <td>2.853225e+08</td>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.907514</td>\n",
       "      <td>0.972807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>6</td>\n",
       "      <td>1.906449e+08</td>\n",
       "      <td>1.878003e+08</td>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>13</td>\n",
       "      <td>1.759023e+08</td>\n",
       "      <td>2.020614e+08</td>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>20</td>\n",
       "      <td>2.128855e+08</td>\n",
       "      <td>1.651399e+08</td>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>27</td>\n",
       "      <td>1.793178e+08</td>\n",
       "      <td>2.357126e+08</td>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.695258</td>\n",
       "      <td>0.696494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>7</td>\n",
       "      <td>1.865516e+08</td>\n",
       "      <td>1.661985e+08</td>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>14</td>\n",
       "      <td>1.847886e+08</td>\n",
       "      <td>2.138389e+08</td>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>21</td>\n",
       "      <td>1.985317e+08</td>\n",
       "      <td>2.097634e+08</td>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>28</td>\n",
       "      <td>1.935864e+08</td>\n",
       "      <td>2.449258e+08</td>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.713014</td>\n",
       "      <td>0.743449</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt report_date  weekday  \\\n",
       "0     1        3.506536e+08      2.781837e+08  2014-09-01      0.0   \n",
       "1     8        3.327267e+08      3.124542e+08  2014-09-08      0.0   \n",
       "2    15        3.282179e+08      2.645074e+08  2014-09-15      0.0   \n",
       "3    22        2.794485e+08      3.321488e+08  2014-09-22      0.0   \n",
       "4    29        2.880849e+08      3.391692e+08  2014-09-29      0.0   \n",
       "5     2        2.756322e+08      2.359720e+08  2014-09-02      1.0   \n",
       "6     9        3.339748e+08      2.785852e+08  2014-09-09      1.0   \n",
       "7    16        3.675868e+08      3.287500e+08  2014-09-16      1.0   \n",
       "8    23        2.733078e+08      3.076282e+08  2014-09-23      1.0   \n",
       "9    30        2.796713e+08      3.317019e+08  2014-09-30      1.0   \n",
       "10    3        3.022276e+08      3.004483e+08  2014-09-03      2.0   \n",
       "11   10        3.674877e+08      2.957898e+08  2014-09-10      2.0   \n",
       "12   17        2.808256e+08      3.202744e+08  2014-09-17      2.0   \n",
       "13   24        2.646811e+08      3.189761e+08  2014-09-24      2.0   \n",
       "14    4        3.123977e+08      3.067058e+08  2014-09-04      3.0   \n",
       "15   11        2.933591e+08      2.720584e+08  2014-09-11      3.0   \n",
       "16   18        2.838634e+08      2.586775e+08  2014-09-18      3.0   \n",
       "17   25        2.604765e+08      3.223097e+08  2014-09-25      3.0   \n",
       "18    5        2.847104e+08      2.657704e+08  2014-09-05      4.0   \n",
       "19   12        2.385152e+08      2.235932e+08  2014-09-12      4.0   \n",
       "20   19        2.520020e+08      2.282084e+08  2014-09-19      4.0   \n",
       "21   26        2.306545e+08      2.853225e+08  2014-09-26      4.0   \n",
       "22    6        1.906449e+08      1.878003e+08  2014-09-06      5.0   \n",
       "23   13        1.759023e+08      2.020614e+08  2014-09-13      5.0   \n",
       "24   20        2.128855e+08      1.651399e+08  2014-09-20      5.0   \n",
       "25   27        1.793178e+08      2.357126e+08  2014-09-27      5.0   \n",
       "26    7        1.865516e+08      1.661985e+08  2014-09-07      6.0   \n",
       "27   14        1.847886e+08      2.138389e+08  2014-09-14      6.0   \n",
       "28   21        1.985317e+08      2.097634e+08  2014-09-21      6.0   \n",
       "29   28        1.935864e+08      2.449258e+08  2014-09-28      6.0   \n",
       "\n",
       "    purchase_weekday  redeem_weekday  \n",
       "0           1.163446        1.226999  \n",
       "1           1.163446        1.226999  \n",
       "2           1.163446        1.226999  \n",
       "3           1.163446        1.226999  \n",
       "4           1.163446        1.226999  \n",
       "5           1.200501        1.178289  \n",
       "6           1.200501        1.178289  \n",
       "7           1.200501        1.178289  \n",
       "8           1.200501        1.178289  \n",
       "9           1.200501        1.178289  \n",
       "10          1.185360        1.154784  \n",
       "11          1.185360        1.154784  \n",
       "12          1.185360        1.154784  \n",
       "13          1.185360        1.154784  \n",
       "14          1.142336        1.037496  \n",
       "15          1.142336        1.037496  \n",
       "16          1.142336        1.037496  \n",
       "17          1.142336        1.037496  \n",
       "18          0.907514        0.972807  \n",
       "19          0.907514        0.972807  \n",
       "20          0.907514        0.972807  \n",
       "21          0.907514        0.972807  \n",
       "22          0.695258        0.696494  \n",
       "23          0.695258        0.696494  \n",
       "24          0.695258        0.696494  \n",
       "25          0.695258        0.696494  \n",
       "26          0.713014        0.743449  \n",
       "27          0.713014        0.743449  \n",
       "28          0.713014        0.743449  \n",
       "29          0.713014        0.743449  "
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#然后做乘法 就得到了预测结果\n",
    "day_pred['total_purchase_amt']*=day_pred['purchase_weekday']\n",
    "day_pred['total_redeem_amt']*=day_pred['redeem_weekday']\n",
    "day_pred#还是有些问题 report_date\t没有按照顺序排列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4输出结果与提交"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>3.506536e+08</td>\n",
       "      <td>2.781837e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>2.756322e+08</td>\n",
       "      <td>2.359720e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>3.022276e+08</td>\n",
       "      <td>3.004483e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.123977e+08</td>\n",
       "      <td>3.067058e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>2.847104e+08</td>\n",
       "      <td>2.657704e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>1.906449e+08</td>\n",
       "      <td>1.878003e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>1.865516e+08</td>\n",
       "      <td>1.661985e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>3.327267e+08</td>\n",
       "      <td>3.124542e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>3.339748e+08</td>\n",
       "      <td>2.785852e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>3.674877e+08</td>\n",
       "      <td>2.957898e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>2.933591e+08</td>\n",
       "      <td>2.720584e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>2.385152e+08</td>\n",
       "      <td>2.235932e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>1.759023e+08</td>\n",
       "      <td>2.020614e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>1.847886e+08</td>\n",
       "      <td>2.138389e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>3.282179e+08</td>\n",
       "      <td>2.645074e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>3.675868e+08</td>\n",
       "      <td>3.287500e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.808256e+08</td>\n",
       "      <td>3.202744e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>2.838634e+08</td>\n",
       "      <td>2.586775e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>2.520020e+08</td>\n",
       "      <td>2.282084e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>2.128855e+08</td>\n",
       "      <td>1.651399e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>1.985317e+08</td>\n",
       "      <td>2.097634e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>2.794485e+08</td>\n",
       "      <td>3.321488e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>2.733078e+08</td>\n",
       "      <td>3.076282e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.646811e+08</td>\n",
       "      <td>3.189761e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>2.604765e+08</td>\n",
       "      <td>3.223097e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>2.306545e+08</td>\n",
       "      <td>2.853225e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>1.793178e+08</td>\n",
       "      <td>2.357126e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>1.935864e+08</td>\n",
       "      <td>2.449258e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>2.880849e+08</td>\n",
       "      <td>3.391692e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>2.796713e+08</td>\n",
       "      <td>3.317019e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   report_date  total_purchase_amt  total_redeem_amt\n",
       "0   2014-09-01        3.506536e+08      2.781837e+08\n",
       "5   2014-09-02        2.756322e+08      2.359720e+08\n",
       "10  2014-09-03        3.022276e+08      3.004483e+08\n",
       "14  2014-09-04        3.123977e+08      3.067058e+08\n",
       "18  2014-09-05        2.847104e+08      2.657704e+08\n",
       "22  2014-09-06        1.906449e+08      1.878003e+08\n",
       "26  2014-09-07        1.865516e+08      1.661985e+08\n",
       "1   2014-09-08        3.327267e+08      3.124542e+08\n",
       "6   2014-09-09        3.339748e+08      2.785852e+08\n",
       "11  2014-09-10        3.674877e+08      2.957898e+08\n",
       "15  2014-09-11        2.933591e+08      2.720584e+08\n",
       "19  2014-09-12        2.385152e+08      2.235932e+08\n",
       "23  2014-09-13        1.759023e+08      2.020614e+08\n",
       "27  2014-09-14        1.847886e+08      2.138389e+08\n",
       "2   2014-09-15        3.282179e+08      2.645074e+08\n",
       "7   2014-09-16        3.675868e+08      3.287500e+08\n",
       "12  2014-09-17        2.808256e+08      3.202744e+08\n",
       "16  2014-09-18        2.838634e+08      2.586775e+08\n",
       "20  2014-09-19        2.520020e+08      2.282084e+08\n",
       "24  2014-09-20        2.128855e+08      1.651399e+08\n",
       "28  2014-09-21        1.985317e+08      2.097634e+08\n",
       "3   2014-09-22        2.794485e+08      3.321488e+08\n",
       "8   2014-09-23        2.733078e+08      3.076282e+08\n",
       "13  2014-09-24        2.646811e+08      3.189761e+08\n",
       "17  2014-09-25        2.604765e+08      3.223097e+08\n",
       "21  2014-09-26        2.306545e+08      2.853225e+08\n",
       "25  2014-09-27        1.793178e+08      2.357126e+08\n",
       "29  2014-09-28        1.935864e+08      2.449258e+08\n",
       "4   2014-09-29        2.880849e+08      3.391692e+08\n",
       "9   2014-09-30        2.796713e+08      3.317019e+08"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#排序  并且只留下 我们想要的特征\n",
    "day_pred=day_pred.sort_values('report_date')[['report_date','total_purchase_amt','total_redeem_amt']]\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "#输出结果\n",
    "day_pred['report_date']=day_pred['report_date'].apply(lambda x:str(x).replace('-','')[0:8])\n",
    "day_pred.to_csv('n_Rule_base.csv',index=False,header=None)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
